home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / dragpic2 / form1.frm next >
Text File  |  1998-04-06  |  5KB  |  193 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   5865
  5.    ClientLeft      =   1275
  6.    ClientTop       =   1530
  7.    ClientWidth     =   3840
  8.    Height          =   6270
  9.    Left            =   1215
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   5865
  12.    ScaleWidth      =   3840
  13.    Top             =   1185
  14.    Width           =   3960
  15.    Begin VB.CheckBox chkUseOutline 
  16.       Caption         =   "Use Outline"
  17.       Height          =   255
  18.       Left            =   120
  19.       TabIndex        =   4
  20.       Top             =   120
  21.       Width           =   1455
  22.    End
  23.    Begin VB.PictureBox picMask 
  24.       AutoRedraw      =   -1  'True
  25.       Height          =   1665
  26.       Left            =   3360
  27.       Picture         =   "Form1.frx":0000
  28.       ScaleHeight     =   107
  29.       ScaleMode       =   3  'Pixel
  30.       ScaleWidth      =   91
  31.       TabIndex        =   2
  32.       Top             =   2640
  33.       Visible         =   0   'False
  34.       Width           =   1425
  35.    End
  36.    Begin VB.PictureBox picImage 
  37.       AutoRedraw      =   -1  'True
  38.       Height          =   1665
  39.       Left            =   3360
  40.       Picture         =   "Form1.frx":739E
  41.       ScaleHeight     =   107
  42.       ScaleMode       =   3  'Pixel
  43.       ScaleWidth      =   91
  44.       TabIndex        =   1
  45.       Top             =   840
  46.       Visible         =   0   'False
  47.       Width           =   1425
  48.    End
  49.    Begin VB.PictureBox picBackground 
  50.       AutoRedraw      =   -1  'True
  51.       Height          =   5385
  52.       Left            =   1680
  53.       Picture         =   "Form1.frx":E73C
  54.       ScaleHeight     =   355
  55.       ScaleMode       =   3  'Pixel
  56.       ScaleWidth      =   251
  57.       TabIndex        =   0
  58.       Top             =   1800
  59.       Visible         =   0   'False
  60.       Width           =   3825
  61.    End
  62.    Begin VB.PictureBox picCanvas 
  63.       AutoRedraw      =   -1  'True
  64.       DrawMode        =   6  'Mask Pen Not
  65.       Height          =   5385
  66.       Left            =   0
  67.       ScaleHeight     =   355
  68.       ScaleMode       =   3  'Pixel
  69.       ScaleWidth      =   251
  70.       TabIndex        =   3
  71.       Top             =   480
  72.       Width           =   3825
  73.    End
  74. End
  75. Attribute VB_Name = "Form1"
  76. Attribute VB_Creatable = False
  77. Attribute VB_Exposed = False
  78. Option Explicit
  79.  
  80. Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
  81. Private Const SRCAND = &H8800C6
  82. Private Const MERGEPAINT = &HBB0226
  83.  
  84. ' Set false to draw the picture. It's slower.
  85. Private UseOutline As Boolean
  86.  
  87. ' The canvas's dimensions.
  88. Private CanvasWid As Single
  89. Private CanvasHgt As Single
  90.  
  91. ' The picture's dimensions.
  92. Private PicWid As Single
  93. Private PicHgt As Single
  94.  
  95. ' The picture's current position.
  96. Private PicX As Single
  97. Private PicY As Single
  98.  
  99. ' Are we dragging?
  100. Private Dragging As Boolean
  101. Private OffsetX As Single
  102. Private OffsetY As Single
  103.  
  104. ' Draw the picture.
  105. Private Sub DrawPic()
  106.     picCanvas.Picture = picBackground.Picture
  107.     
  108. '    picCanvas.PaintPicture picMask.Picture, _
  109. '        PicX, PicY, PicWid, PicHgt, _
  110. '        0, 0, PicWid, PicHgt, vbMergePaint
  111.     BitBlt picCanvas.hDC, _
  112.         PicX, PicY, PicWid, PicHgt, _
  113.         picMask.hDC, _
  114.         0, 0, MERGEPAINT
  115.     
  116. '    picCanvas.PaintPicture picImage.Picture, _
  117. '        PicX, PicY, PicWid, PicHgt, _
  118. '        0, 0, PicWid, PicHgt, vbSrcAnd
  119.     BitBlt picCanvas.hDC, _
  120.         PicX, PicY, PicWid, PicHgt, _
  121.         picImage.hDC, _
  122.         0, 0, SRCAND
  123.  
  124.     picCanvas.Picture = picCanvas.Image
  125. End Sub
  126.  
  127. ' Draw an outline of the picture.
  128. Private Sub DrawOutline()
  129.     picCanvas.Line _
  130.         (PicX, PicY)-Step(PicWid, PicHgt), , B
  131. End Sub
  132.  
  133. ' Draw the initial picture.
  134. Private Sub Form_Load()
  135.     CanvasWid = picCanvas.ScaleWidth
  136.     CanvasHgt = picCanvas.ScaleHeight
  137.     PicWid = picImage.ScaleWidth
  138.     PicHgt = picImage.ScaleHeight
  139.     PicX = PicWid
  140.     PicY = PicHgt
  141.     DrawPic
  142. End Sub
  143.  
  144.  
  145.  
  146. ' See if the mouse is over a point corresponding
  147. ' to a black part of the mask.
  148. Private Sub picCanvas_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  149.     OffsetX = PicX - x
  150.     OffsetY = PicY - y
  151.     If picMask.Point(-OffsetX, -OffsetY) <> vbBlack Then Exit Sub
  152.     
  153.     ' Start dragging.
  154.     UseOutline = (chkUseOutline.Value = vbChecked)
  155.     If UseOutline Then DrawOutline
  156.     Dragging = True
  157. End Sub
  158.  
  159. ' Drag.
  160. Private Sub picCanvas_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  161.     If Not Dragging Then Exit Sub
  162.     
  163.     If UseOutline Then DrawOutline
  164.  
  165.     PicX = x + OffsetX
  166.     If PicX < 0 Then
  167.         PicX = 0
  168.     ElseIf PicX > CanvasWid - PicWid Then
  169.         PicX = CanvasWid - PicWid
  170.     End If
  171.     
  172.     PicY = y + OffsetY
  173.     If PicY < 0 Then
  174.         PicY = 0
  175.     ElseIf PicY > CanvasHgt - PicHgt Then
  176.         PicY = CanvasHgt - PicHgt
  177.     End If
  178.     
  179.     If UseOutline Then
  180.         DrawOutline
  181.     Else
  182.         DrawPic
  183.     End If
  184. End Sub
  185.  
  186. ' Stop dragging.
  187. Private Sub picCanvas_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  188.     If UseOutline Then DrawPic
  189.     Dragging = False
  190. End Sub
  191.  
  192.  
  193.